package com.amap.poi.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.amap.poi.common.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 异步服务实现
 */
@Component
@Slf4j
public class AsyncServiceImpl {

    @Autowired
    private RedisUtils redisUtils;

    /**
     * 异步设置缓存
     *
     * @param redisKey
     * @param jsonStr
     */
    @Async
    public void asyncSetCache(String redisKey, String jsonStr) {
        // 设置随机过期时间范围
        int expirationTime = RandomUtil.randomInt(600, 1800);
        redisUtils.set(redisKey, jsonStr, expirationTime);
    }

    /**
     * 异步设置缓存
     *
     * @param redisKey
     * @param list
     */
    @Async
    public void asyncSetCache(String redisKey, List list) {
        // 设置随机过期时间范围
        int expirationTime = RandomUtil.randomInt(600, 1800);
        redisUtils.lSet(redisKey, list, expirationTime);
    }

}
